package cn.lyf.myblog.controller.api;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.node.*;
import static cn.lyf.myblog.controller.api.JsonUtils.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import cn.lyf.myblog.service.LikeService;

@RestController
public class MessageApi {

    @Autowired
    LikeService likeService;

    // 获取点赞信息
    @GetMapping("/message/like")
    JsonNode getLikes(@RequestBody JsonNode json) throws Exception {
        ObjectNode res = mapper.createObjectNode();
        res.put("success", true);
        res.put("code", 200);
        res.put("message", "点赞消息获取成功！");
        res.set("result", likeService.getLikesList(json));
        return res;
    }

    // 已读点赞信息
    @PutMapping("/message/like")
    @Transactional(rollbackFor = Exception.class)
    JsonNode readLikes(@RequestBody JsonNode json) throws Exception {
        return likeService.readLike(json);
    }

    // 删除点赞信息
    @DeleteMapping("/message/like")
    @Transactional(rollbackFor = Exception.class)
    JsonNode clearLikes(@RequestBody JsonNode json) throws Exception {
        return likeService.hideLike(json);
    }
}
